def cnt4():
    for i in [a, b]:
        for j in [c, d]:
            for k in [e, f]:
                if i == j == k:
                    return True
                if i == j and a + b + c + d - i -j == k:
                    return True
                if i == k and a + b + e + f - i -k == j:
                    return True
                if k == j and e + f + c + d - k -j == i:
                    return True
    return False

def cnt6():
    for i in [a, b]:
        for j in [c, d]:
            for k in [e, f]:
                if i ==j or i == k or j == k:
                    return True
                if i + j == k or i + k == j or j + k == i:
                    return True
    return False

t = int(input())
for _ in range(t):
    a, b, c, d, e, f = map(int ,input().split())
    if cnt4():
        print(4)
    elif cnt6():
        print(6)
    else:
        print(8)
